<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="se" uri="http://zc.security/acl"%> 
<div class="easyui-layout" style="width:100%;height:100%;" fit="true">
	<div data-options="region:'north',title:'信息管理',split:true" style="height:70px;background-color:#e6edfd;">
    	<form action="" id="searchForm" name="searchForm">
    	<table class="screen">
			<tr>
				<td class="screen-n"><span>标题</span></td>
				<td class="screen-n">
					<input type="text" id="s_complaintTitle" class="screen-input"  onkeydown="pms.kd13('initList')" style="width:200px;">
				</td>
				<td class="screen-n">
					<input type="button" class="button" value="查询" onclick="initList()">
					<input type="button" class="button" value="重置" onclick="pms.resetForm('searchForm');initList();" >
				    <input type="button" class="button" value="导出" onclick="loadExecl('initStoreOutCheckTableExcel')" >
				</td>
			</tr>
		</table>
		</form>
    </div>
    
    
    <div id="toolbar" style="display: none;">
    	<table>
		<tr>
			<se:hasPermissions actCode="DELETE" >
			<td>
				<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-note_delete',plain:true" onclick="deleteRecords();">删除</a>
			</td>
			</se:hasPermissions>
			<se:hasPermissions actCode="APPROVE" >
			<td>
			   <a href="#" class="easyui-menubutton" data-options="menu:'#mm1',iconCls:'ext-icon-key',plain:true">批量审核</a>
		        <div id="mm1">
			    	<div data-options="iconCls:'icon-redo'" onclick="changenStatusBat('status',1);">批量审核</div>
			        <div data-options="iconCls:'icon-undo'" onclick="changenStatusBat('status',0);">取消审核</div>
			    </div>
			</td>
			</se:hasPermissions>
			
		</tr>
	</table>
    
    </div>
    
    <div data-options="region:'center',split:true" style="width: 100%;height: 100%">
		<table id="tableGrid"></table>
	</div>
</div>
<script>
function openAddWindow(){
	$.pmsDialog({
		id:"w_form",
		title:'新增',
		method:'post',
		href:'<c:url value="/views/jsp/complaint/form.jsp"/>',
		fit:true,
	});
}

// 批量属性
function changenStatusBat(type,value){
	var rows = tbl.getSelectedData();
	if(rows.length>0){
		if(confirm("确定批量操作?")){
			var ids = [];
			for(var i=0; i<rows.length; i++){
				ids.push(rows[i].complaintId);
			}

			var complaintIDList = ids.toString();
			
			var param = {};
			param[type] = value;
			param["complaintIDList"] = complaintIDList;
			console.log(param);
			$.pmsAjax({
				url:'<c:url value="/complaint/updateEmBComplaintBat.do"/>',
				data:param,
				success:function(data){
					if(data.code==200){
						alertShow("批处理成功");
						initList();
					}else{
						alertError(data.resultMessage);
					}
				}
			}); 
		}
	}else{
		alertError('请选择操作记录');
	}
}

// 单个属性
function changenStatus(complaintId,type,value){
	if(value!=1){
		value = 1;
	}else{
		value = 0;
	}
	
	var param = {};
	param[type] = value;
	param["complaintId"] = complaintId;
	
	$.pmsAjax({
		url:'<c:url value="/complaint/updateEmBComplaint.do"/>',
		data:param,
		success:function(data){
			if(data.code==200){
				initList();
			}else{
				alertError(data.resultMessage);
			}
		}
	}); 
}

function openUpdateWindow(complaintId){
	var params = {"complaintId":complaintId}
	$.pmsDialog({
		id:"w_form",
		title:'查看详情',
		method:'post',
		params:params,
		href:'<c:url value="/views/jsp/complaint/form.jsp"/>',
		width:700,
		height:350
		 
	});
}

function deleteRecords(){
	var rows = tbl.getSelectedData();
	if(rows.length>0){
		if(confirm("确定批量删除?")){
			var ids = [];
			for(var i=0; i<rows.length; i++){
				ids.push(rows[i].complaintId);
			}
			var complaintIdList = ids.toString();
			var param = {"complaintIdList":complaintIdList};
			$.pmsAjax({
				url:'<c:url value="/complaint/deleteMultipleEmBComplaint.do"/>',
				data:param,
				success:function(data){
					if(data.code==200){
						alertShow("删除批量成功");
						initList();
					}else{
						alertError(data.resultMessage);
					}
				}
			});
		}
	}else{
		alertError('请选择操作记录');
	}
	
}


function replay(complaintId,createUser,userName){
	var params = {"complaintId":complaintId,"createUser":createUser,"userName":userName}
	$.pmsDialog({
		id:"w_list",
		isIf:'true',
		title:'回复',
		method:'post',
		params:params,
		href:'<c:url value="/views/jsp/complaint/reply_s.jsp"/>',
		width:800,
		height:650
	});
	
}

function deleteRecord(complaintId,i){
	if(confirm("确定删除记录?")){
		var param = {"complaintId":complaintId};
		$.pmsAjax({
			url:'<c:url value="/complaint/deleteEmBComplaint.do"/>',
			data:param,
			success:function(data){
				if(data.code==200){
					alertShow("删除记录成功");
					/*
					疑问：tbl.removeRow(i)；没有调用成功，目前只能整个页面刷新
					*/
					//tbl.removeRow(i);
					initList();
					
				}else{
					alertError(data.resultMessage);
				}
			}
		});
	}
}

var tbl;
$(function(){
	initList();
});
function getParams(){
	var queryParamss = {
			"complaintTitle":$("#s_complaintTitle").val()
	    };
    return queryParamss;
}
function initList(){
	tbl = $('#tableGrid').pDataGrid({
		 toolbar : '#toolbar',
		 columns:[[
		          {field:'ck',checkbox:true},
				  {field:'complaintTitle',title:'标题',sortable:true,align:'center'},
				  {field:'createUser',title:'发布人',sortable:true},
				  {field:'userName',title:'发布人名称',sortable:true},
				  {field:'connectPhone',title:'联系电话',sortable:true},
                  {
                      field: 'createDate', title: '发布时间', width: 100,sortable: true,
                      formatter : function(value){
                          var date = new Date(value);
                          var y = date.getFullYear();
                          var m = date.getMonth() + 1;
                          var d = date.getDate();
                          return y + '-' +m + '-' + d;
                      }
                  },
				  {field:'isSatisfaction',title:'是否满意',sortable:true,align:'center'},
				  {field:'status',title:'状态',sortable:true,align:'center',
					  formatter : function(value) {
						  str = "";
						  if(value==0){
							  str = "未审核"
						  }else{
							  str = "已审核";
						  }
						  return str;
					  }
				  },
				  {field:'repplyStatus',title:'回复状态',sortable:true,align:'center',
					  formatter : function(value) {
						  str = "";
						  if(value==0){
							  str = "未回复"
						  }else{
							  str = "已回复";
						  }
						  return str;
					  }
				  },
				  
				  {
						title : '操作',
						field : 'action',
						align : 'center',
						formatter : function(value, row, index) {
							var str = '';
								
								str += ' <img class="iconImg ext-icon-note_edit" title="查看" onclick="openUpdateWindow('+row.complaintId+');"/>';
								<se:hasPermissions actCode="DELETE" >
								str += ' <img class="iconImg ext-icon-note_delete" title="删除" onclick="deleteRecord('+row.complaintId+',' + index + ');"/>';
								</se:hasPermissions>  
								<se:hasPermissions actCode="APPROVE" >
								str += ' <img class="iconImg ext-icon-key" title="审核" onclick="changenStatus('+row.complaintId+',\'status\','+row.status+');"/>';
								</se:hasPermissions>  
								<se:hasPermissions actCode="APPROVE" >
								str += ' <img class="iconImg ext-icon-comments" title="回复" onclick="replay('+row.complaintId+',' + row.createUser +',\'' + row.userName + '\');"/>';
								</se:hasPermissions>  
							return str;
						}
					} 
				  ]
			  ],
		    url:'<c:url value="/complaint/searchPageEmBComplaint.do"/>',  
		    pagination:true,
		    pageSize:30,
		    fitColumns:false,
		    singleSelect:false,
		    queryParams:getParams(),
		    completeCallback:function(data){
				if(data.resultCode == "100"){
					alertError(data.errorMsg);
				} 
			},
			onDblClickRow:function(index,row){
				openUpdateWindow(row.complaintId);
			},
			onLoadSuccess : function(data) {
				var panel = $(this).datagrid('getPanel');
				var tr = panel.find('div.datagrid-body tr');
				tr.each(function() {
					var td = $(this).children('td[field="complaintTitle"]');
					td.children("div").css({
						"text-align" : "left"
					});
				});
			}
	}); 
	
}
//导出
function initStoreOutCheckTableExcel(){
	loadExcelCallBack('<c:url value="/complaint/searchPageEmBComplaintExcel.do"/>',getParams());
} 
</script>
